//
//  ZyyCollectionViewCell.swift
//  swift各类控件集锦
//
//  Created by iosdev1 on 2017/5/4.
//  Copyright © 2017年 zyy. All rights reserved.
//

import UIKit

protocol ZyyCollectionViewCellDelegate {
    func menuItemFunc1(string:String, forString:String)
    func menuItemFunc2(string:String, forString:String)
    func menuItemFunc3(string:String, forString:String)
    func menuItemFunc4(string:String, forString:String)
    func customAction(string:String, forString:String)
}

class ZyyCollectionViewCell: UICollectionViewCell {
    var lblTitle:UILabel! = nil
    var btnAdd:UIButton! = nil

    var delegate : ZyyCollectionViewCellDelegate?

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        print("初始化成功")
        self.initView()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func initView() -> Void {
        self.backgroundColor = UIColor.red
        lblTitle = UILabel.init(frame: CGRect(x:10, y:10, width:100, height:30))
        self.addSubview(lblTitle)
        lblTitle.backgroundColor = UIColor.blue
        lblTitle.textColor = UIColor.white
        lblTitle.text = "title"
        
        btnAdd = UIButton.init(frame: CGRect(x:10, y:50, width:100, height:30))
        self.addSubview(btnAdd)
        btnAdd.backgroundColor = UIColor.red
        btnAdd.setTitle("改变title", for: UIControlState.normal)
        btnAdd.addTarget(self, action: #selector(btnAddClick(btn:)), for: UIControlEvents.touchUpInside)
    }
    
    func btnAddClick(btn:UIButton) -> Void {
        print("改变了title")
        lblTitle.text = "改变了title"
    }
    
    
    func setTitle(title:String) -> Void {
        lblTitle.text = title
    }
    
    //    MARK: customAction
    func customAction(sender:Any) -> Void {        
        delegate?.customAction(string: "customAction", forString: "diewr")
    }
    
    func menuItemFunc1(sender:Any) -> Void {
        print("hello")
        delegate?.menuItemFunc1(string: "menuItemFunc1", forString: "sss")
    }
    
    func menuItemFunc2(sender:Any) -> Void {
        print("hello")
        delegate?.menuItemFunc2(string: "menuItemFunc2", forString: "sss")
    }
    
    func menuItemFunc3(sender:Any) -> Void {
        print("hello")
        delegate?.menuItemFunc3(string: "menuItemFunc3", forString: "sss")
    }
    
    func menuItemFunc4(sender:Any) -> Void {
        print("hello")
        delegate?.menuItemFunc4(string: "menuItemFunc4", forString: "sss")
    }

}
